<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form
      ref="form"
      size="mini"
      :model="form"
      label-position="top"
      class="myform"
    >
      <div>
        <el-form-item label="加工单号/采购单:" class="myform-item">
          <el-input
            v-model="form.processing_code"
            placeholder="请输入加工单号或采购单"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="SKU:" class="myform-item">
          <el-input
            v-model="form.sku_code"
            placeholder="请输入SKU"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="工厂名:" class="myform-item">
          <el-input
            v-model="form.factory_name"
            placeholder="请输入工厂名"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="RFID生成状态:" class="myform-item">
          <el-select
            v-model="form.is_create"
            placeholder="请选择RFID生成状态"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="完结状态:" class="myform-item">
          <el-select
            v-model="form.f_status"
            placeholder="请选择完结状态"
            clearable
          >
            <el-option
              v-for="item in optionsWJ"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态:" class="myform-item">
          <el-select
            v-model="form.s_status"
            placeholder="请选择审核状态"
            clearable
          >
            <el-option
              v-for="item in optionsSH"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推送状态:" class="myform-item">
          <el-select
            v-model="form.is_oms"
            placeholder="请选择推送状态"
            clearable
          >
            <el-option
              v-for="item in optionsTS"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下单日期">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="form.str_add_date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item style="margin: 36px 10px 0">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <!-- <el-button type="primary" @click="onAdd">新增面料</el-button> -->
        </el-form-item>
        <el-form-item style="margin-top: 36px">
          <el-button type="primary" @click="onExport">导出</el-button>
          <!-- <el-button type="primary" @click="onAdd">新增面料</el-button> -->
        </el-form-item>
        <el-form-item style="margin-top: 36px; margin-left: 10px">
          <el-button type="primary" @click="onExportYY">运营导出</el-button>
          <!-- <el-button type="primary" @click="onAdd">新增面料</el-button> -->
        </el-form-item>
      </div>
    </el-form>
    <div style="margin: 20px 0">
      <el-button type="primary" size="mini" @click="onUpdate"
        >更新成品加工单</el-button
      >
      <span style="margin-left: 20px; font-size: 14px"
        >最后更新日期：{{ savetime }}</span
      >
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      :height="browserHeight - 350"
      :summary-method="getSummaries"
      show-summary
      border
      :cell-style="cellStyle"
      :header-cell-style="headerCellStyle"
      size="mini"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" fixed> </el-table-column>
      <el-table-column
        label="RFID状态"
        align="center"
        prop="groups"
        width="100"
        fixed
      >
        <template slot-scope="{ row }">
          <div>
            {{ row.groups == 1 ? "水洗唛" : row.groups == 2 ? "吊牌" : "其他" }}
          </div>
          <div :style="{ color: row.is_create == 1 ? '#67C23A' : '' }">
            {{
              row.is_create == 0
                ? "未设置"
                : row.is_create == 1
                ? "已生成"
                : "无需生成"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="成品加工单编码"
        align="center"
        prop="processing_code"
        width="140"
        fixed
      >
        <template slot-scope="{ row }">
          <div>
            <div>{{ row.processing_code }}</div>
            <div style="display: flex; align-items: center">
              <div
                style="padding: 4px; color: #ffffff; width: 80px"
                :style="{ background: row.f_status == 0 ? 'red' : '#67C23A' }"
              >
                {{ row.f_status == 0 ? "进行中" : "已完成" }}
              </div>
              <div
                :style="{ color: row.status == 0 ? 'red' : '#67C23A' }"
                style="margin-left: 10px"
              >
                {{ row.status == 0 ? "禁用" : "正常" }}
              </div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="采购单号"
        align="center"
        prop="jy_number"
        width="180"
        fixed
      >
        <template slot-scope="{ row }">
          <div v-if="row.jy_purchase_number">{{ row.jy_purchase_number }}</div>
          <div v-if="row.po_id">{{ row.po_id }}</div>
        </template>
      </el-table-column>
      <el-table-column label="款号/SKU" prop="type_no" width="150" fixed>
        <template slot-scope="{ row }">
          <div style="display: flex">
            <div v-if="row.type_no" style="width: 92px">
              <span
                style="color: #2c70d6"
                class="pointer"
                @click="clicktype_no(row.type_no)"
                >{{ row.type_no }}</span
              >
              <div v-if="row.sku_code" style="font-weight: 600">
                <span>{{ row.sku_code }}</span>
              </div>
            </div>
            <el-image
              :src="cccx"
              fit="contain"
              style="width: 25px; margin-left: 10px"
              class="pointer"
              @click="onPocessingKC(row)"
            ></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="s_status" fixed>
        <template slot-scope="{ row }">
          <div
            :style="{
              color:
                row.s_status == 1
                  ? '#67C23A'
                  : row.s_status == 2
                  ? '#F56C6C'
                  : row.s_status == 3
                  ? '#E6A23C'
                  : '',
            }"
          >
            {{
              row.s_status == 1
                ? "已审核"
                : row.s_status == 0
                ? "未审核"
                : row.s_status == 2
                ? "已结案"
                : row.s_status == 3
                ? "已同步"
                : ""
            }}
          </div>
          <div
            :style="{
              color: row.is_oms == 1 ? '#67C23A' : '',
            }"
          >
            {{ row.is_oms == 0 ? "未推送" : "已推送" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="下单数" align="center" prop="num">
      </el-table-column>
      <el-table-column label="增裁数" align="center" prop="zc_num">
      </el-table-column>
      <el-table-column label="报次数" align="center" prop="bao_number">
      </el-table-column>
      <el-table-column label="溢装比数" align="center" prop="yc_num">
      </el-table-column>
      <el-table-column label="入库数" align="center" prop="qty">
        <template slot-scope="{ row }">
          <el-button type="text" size="default" @click="ClickQty(row)">{{
            row.qty
          }}</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="聚水潭-巨益(入库数)"
        align="center"
        prop="jsy_qty"
      >
      </el-table-column> -->
      <el-table-column label="未入库数" align="center" prop="wrks">
      </el-table-column>
      <el-table-column
        label="合同号/供应商"
        width="170"
        prop="factory_contract_no"
      >
        <template slot-scope="{ row }">
          <div
            v-if="row.factory_contract_no"
            style="color: #2c70d6"
            class="pointer"
            @click="clickfactory_contract_no(row.factory_contract_no)"
          >
            {{ row.factory_contract_no }}
          </div>
          <div v-if="row.factory_name">{{ row.factory_name }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="合同交期/批次"
        prop="contract_date"
        align="center"
        width="120"
      >
        <template slot-scope="{ row }">
          <div v-if="row.contract_date">交：{{ row.contract_date }}</div>
          <div v-if="row.batch_date">批：{{ row.batch_date }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="大货核价编码"
        align="center"
        prop="verify_price_number"
      >
      </el-table-column>
      <el-table-column label="总价" align="center" prop="countprice">
      </el-table-column>
      <el-table-column label="预付款" align="center" prop="advance_charge">
      </el-table-column>
      <el-table-column label="绣花厂" align="center" prop="embroidery_factory">
      </el-table-column>
      <el-table-column
        label="绣花厂单价"
        align="center"
        prop="embroidery_price"
      >
      </el-table-column>

      <el-table-column
        label="生产回复交期"
        align="center"
        prop="production_date"
      >
      </el-table-column>

      <el-table-column label="跟单人" align="center" prop="merchandiser">
      </el-table-column>
      <el-table-column label="理单人" align="center" prop="order_processor">
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="adduser">
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createtime"
        width="110"
      >
      </el-table-column>

      <el-table-column label="印花厂" align="center" prop="printing_factory">
      </el-table-column>
      <el-table-column label="烫金厂" align="center" prop="bronzing_factory">
      </el-table-column>
      <el-table-column
        label="印金厂"
        align="center"
        prop="gold_printing_factory"
      >
      </el-table-column>
      <el-table-column label="SKU单价" align="center" prop="unit_price">
      </el-table-column>
      <el-table-column label="客人下单日期" align="center" prop="add_date">
      </el-table-column>

      <el-table-column label="操作" align="center" fixed="right" width="220">
        <template slot-scope="{ row }">
          <!-- <el-button
            type="text"
            @click="onPush(row.id)"
            size="mini"
            v-if="row.j_status == 0 && row.s_status != 0"
            >推送</el-button
          > -->
          <el-button
            type="text"
            @click="onPush(row.processing_code)"
            v-if="
              row.is_oms == 0 &&
              row.s_status != 0 &&
              row.status == 1 &&
              row.f_status == 0
            "
            size="mini"
            >推送</el-button
          >
          <el-button
            type="text"
            style="color: red"
            v-if="row.is_oms != 0 && row.s_status != 0 && row.status == 1"
            @click="onCancel(row.processing_code)"
            >取消</el-button
          >
          <el-button
            type="text"
            style="color: red"
            v-if="row.is_oms == 0 && row.status == 1"
            @click="onDisable(row.processing_code, 1)"
            >禁用</el-button
          >
          <el-button
            type="text"
            v-if="row.is_oms == 0 && row.status == 0"
            @click="onDisable(row.processing_code, 0)"
            >启用</el-button
          >
          <el-button
            v-if="row.status == 1"
            type="text"
            size="mini"
            @click="onReturn(row, 0)"
            >采退</el-button
          >
          <el-button
            v-if="row.status == 1"
            type="text"
            size="mini"
            @click="onReturn(row, 1)"
            >返修</el-button
          >
          <el-button
            type="text"
            size="mini"
            v-if="row.f_status == 0 && row.status == 1"
            @click="onBao(row)"
            >报次</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="onPocessingPc(row)"
            v-if="row.f_status == 0 && row.status == 1"
            >批次</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="onPocessingZc(row)"
            v-if="
              row.source_type != 5 && row.source_type != 6 && row.status == 1
            "
            >增裁</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="onPocessingFstatus(row)"
            v-if="row.f_status == 0 && row.status == 1"
            >强制完成</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px">
      <el-button
        type="primary"
        :disabled="!multipleSelection.length"
        size="mini"
        @click="onCreate(1)"
        >生成RFID洗水唛</el-button
      >
      <el-button
        type="primary"
        :disabled="!multipleSelection.length"
        size="mini"
        @click="onCreate(3)"
        >生成RFID吊牌</el-button
      >
      <el-button
        type="primary"
        :disabled="!multipleSelection.length"
        size="mini"
        @click="onCreate(2)"
        >无需生成RFID</el-button
      >

      <el-dialog
        :title="groups == 0 ? '发起采购退货' : '发起返厂维修'"
        :visible.sync="dialogVisible"
        width="800px"
      >
        <div>
          <div
            style="
              display: flex;
              justify-content: space-between;
              margin-bottom: 10px;
            "
          >
            <div>成品加工单：{{ row.processing_code }}</div>
            <div>供应商：{{ row.factory_name }}</div>
          </div>
          <el-table
            height="300"
            :data="tableReturn"
            border
            size="mini"
            style="width: 100%"
            ref="textDocRef"
            @selection-change="handleSelectionChangeTH"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column prop="type_no" align="center" label="款号">
            </el-table-column>
            <el-table-column prop="type_name" align="center" label="款名">
            </el-table-column>
            <el-table-column prop="sku_code" align="center" label="SKU">
            </el-table-column>
            <el-table-column
              prop="num"
              align="center"
              :label="groups == 0 ? '计划退货数' : '计划返厂数'"
            >
              <template slot-scope="{ row, $index }">
                <el-input
                  type="number"
                  v-model="row.num"
                  placeholder="0"
                  size="mini"
                  @input="onInput($event, row, $index)"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleCloseR" size="mini">取 消</el-button>
          <el-button
            type="primary"
            :disabled="!multipleSelection.length"
            @click="onOK"
            size="mini"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <el-dialog
        title="报次数"
        :visible.sync="dialogVisibleB"
        width="800px"
        :before-close="handleCloseR"
      >
        <div>
          <div
            style="
              display: flex;
              justify-content: space-between;
              margin-bottom: 10px;
            "
          >
            <div>成品加工单：{{ row.processing_code }}</div>
            <div>供应商：{{ row.factory_name }}</div>
          </div>
          <el-table
            height="300"
            :data="tableReturn"
            border
            size="mini"
            style="width: 100%"
            ref="textDocRef"
            @selection-change="handleSelectionChangeTH"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column prop="type_no" align="center" label="款号">
            </el-table-column>
            <el-table-column prop="type_name" align="center" label="款名">
            </el-table-column>
            <el-table-column prop="sku_code" align="center" label="SKU">
            </el-table-column>
            <el-table-column prop="num" align="center" label="报次数">
              <template slot-scope="{ row, $index }">
                <el-input
                  type="number"
                  v-model="row.num"
                  placeholder="0"
                  size="mini"
                  @input="onInput($event, row, $index)"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleCloseR" size="mini">取 消</el-button>
          <el-button
            type="primary"
            :disabled="!multipleSelection.length"
            @click="onOKBao"
            size="mini"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>

    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminCodeGetpocessingcodelist"
    />
    <el-dialog
      title="请选择工厂"
      :visible.sync="dialogVisibleExport"
      width="30%"
    >
      <div>
        <el-select v-model="supplier_id" placeholder="请选择" clearable>
          <el-option
            v-for="item in factoryList"
            :key="item.supplier_id"
            :label="item.factory_name"
            :value="item.supplier_id"
          >
          </el-option>
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleExport = false">取 消</el-button>
        <el-button
          type="primary"
          :disabled="!supplier_id"
          @click="onExportSubmit"
          >导 出</el-button
        >
      </span>
    </el-dialog>
    <el-dialog title="设置批次" :visible.sync="dialogVisiblePC" width="30%">
      <div>
        <el-select v-model="batch_id" placeholder="请选择" clearable>
          <el-option
            v-for="item in pclist"
            :key="item.id"
            :label="item.batch_date"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisiblePC = false">取 消</el-button>
        <el-button
          type="primary"
          :disabled="!batch_id"
          @click="onExportSubmitPc"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="增裁补码"
      :visible.sync="dialogVisibleZC"
      width="800px"
      :before-close="handleCloseR"
    >
      <div>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
          "
        >
          <div>成品加工单：{{ row.processing_code }}</div>
          <div>款号：{{ row.type_no }}</div>
          <div>款名：{{ row.type_name }}</div>
        </div>
        <el-table
          height="300"
          :data="tableReturn"
          border
          size="mini"
          style="width: 100%"
          ref="textDocRef"
          @selection-change="handleSelectionChangeTH"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="sku_code" align="center" label="SKU">
          </el-table-column>
          <el-table-column prop="num" align="center" label="增裁补码数量">
            <template slot-scope="{ row, $index }">
              <el-input
                type="number"
                v-model="row.num"
                placeholder="0"
                size="mini"
                @input="onInput($event, row, $index)"
              ></el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseR" size="mini">取 消</el-button>
        <el-button
          type="primary"
          :disabled="!multipleSelection.length"
          @click="onExportSubmitZc"
          :loading="loading"
          size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="商品库存"
      :visible.sync="dialogVisibleKC"
      width="800px"
      :before-close="handleCloseR"
    >
      <div>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
          "
        >
          <!-- <div>成品加工单：{{ row.processing_code }}</div> -->
          <div>款号：{{ row.type_no }}</div>
          <div>款名：{{ row.type_name }}</div>
        </div>
        <el-table
          height="300"
          :data="tableReturn"
          border
          size="mini"
          style="width: 100%"
          ref="textDocRef"
        >
          <el-table-column prop="product_code" align="center" label="SKU">
          </el-table-column>
          <el-table-column prop="num" align="center" label="库存">
          </el-table-column>
          <el-table-column prop="use_num" align="center" label="可销数">
            <template slot-scope="{ row }"
              ><span
                style="font-weight: 600"
                :style="{ color: row.use_num > 0 ? 'red' : '#67C23A' }"
                >{{ row.use_num || 0 }}</span
              ></template
            >
          </el-table-column>
        </el-table>
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseR" size="mini">取 消</el-button>
        <el-button
          type="primary"
          :disabled="!multipleSelection.length"
          @click="onExportSubmitZc"
          :loading="loading"
          size="mini"
          >确 定</el-button
        >
      </span> -->
    </el-dialog>
  </div>
</template>

<script>
import { getStore } from "@/utils/localStorage.js";
import cccx from "@/assets/images/cccx.png";
import {
  postAdminOperateSetprocess_batch,
  postAdminOperateGetbatch,
  postAdminCodeGetpocessingcodelist,
  postAdminCodeSetpocessingcodestatus,
  postAdminCodeSetJushuitanPurchaseUpload_shou,
  postAdminOmsaddWarehousingProcessing,
  postAdminOmscancelProcessing,
  postAdminOperatesave_processing_order,
  postAdminOmsGetProType,
  postAdminOmsSetPurchaseReturn,
  postAdminCodeSetpocessingFstatus,
  postAdminProductionSaveBaonumber,
  postAdminExcelProcessingWeiruku,
  postHomeCodeGetFactory,
  postAdminCodeSetshenqing,
  postCodegetPocessinglist,
  postAdminOperateget_jyamout,
  postAdminCodegetprocessing_to_void,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dialogVisibleB: false,
      dialogVisibleList: false,
      dialogVisibleExport: false,
      dialogVisiblePC: false,
      dialogVisibleZC: false,
      dialogVisibleKC: false,
      cccx,
      groups: 0, // 0采退    1返厂
      row: "",
      browserHeight: "",
      savetime: "",
      factoryList: [],
      supplier_id: "",
      batch_id: "",
      processing_code: "",
      optionsSH: [
        {
          value: "0",
          label: "未审核",
        },
        {
          value: "1",
          label: "已审核",
        },
        {
          value: "2",
          label: "已结案",
        },
        {
          value: "3",
          label: "已同步",
        },
      ],
      optionsTS: [
        {
          value: "0",
          label: "未推送",
        },
        {
          value: "1",
          label: "已推送",
        },
      ],
      options: [
        {
          value: "0",
          label: "未设置",
        },
        {
          value: "1",
          label: "已生成",
        },
        {
          value: "2",
          label: "无需生成",
        },
      ],
      optionsWJ: [
        {
          value: "0",
          label: "进行中",
        },
        {
          value: "1",
          label: "完结",
        },
      ],
      form: {
        processing_code: "",
        sku_code: "",
        is_create: "",
        f_status: "",
        factory_name: "",
        str_add_date: "",
        end_add_date: "",
        is_oms: "",
        s_status: "",
        page: 1,
        size: 10,
      },

      multipleSelection: [],
      tableData: [],
      total: 1,
      row: "",
      tableReturn: [],
      pclist: [],
      userinfo: "",
    };
  },
  activated() {
    this.browserHeight =
      window.innerHeight ||
      document.documentElement.clientHeight ||
      document.body.clientHeight;
    this.form.order_processor = getStore("userinfo").username;
    let form = this.form;
    this.postAdminCodeGetpocessingcodelist(form);
    this.postHomeCodeGetFactory();
    this.postAdminOperateGetbatch();
    this.userinfo = getStore("userinfo");
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.multipleTable.doLayout();
    });
  },
  methods: {
    async onDisable(processing_code, type) {
      let data = {
        processing_code,
      };
      this.$confirm(
        `此操作将${type == 1 ? "禁用" : "启用"}该加工单, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(async () => {
          try {
            await postAdminCodegetprocessing_to_void(data);
            let form = this.form;
            this.postAdminCodeGetpocessingcodelist(form);
          } catch (error) {}
        })
        .catch(() => {});
    },
    async clicktype_no(e) {
      let number = await this.encrypt(e);
      this.$router.push({
        name: `CustomModuleRouter`,
        params: { path: `/CustomModuleDesignFilesDetail/${number}` },
      });
    },
    clickfactory_contract_no(e) {
      let roletop = this.userinfo.roletop;
      let qxobj = "";

      for (let index = 0; index < roletop.length; index++) {
        if (roletop[index].name == "成衣厂对账单") {
          for (let idx = 0; idx < roletop[index].list.length; idx++) {
            if (roletop[index].list[idx].name == "合同列表") {
              qxobj = {};
              let qx = roletop[index].list[idx].qx;
              qx.forEach((element) => {
                qxobj[element.rolekey] = 1;
              });
              qxobj = JSON.stringify(qxobj);
            }
          }
        }
      }
      if (qxobj) {
        this.$router.push({
          name: "Contractlist",
          query: { qxobj },
          params: { factory_contract_no: e },
        });
      } else {
        this.$message.warning("暂无查看权限！");
      }
    },
    async onExportSubmitPc() {
      this.loading = true;
      let { batch_id, processing_code } = this;
      let obj = {
        batch_id,
        processing_code,
      };
      try {
        let res = await postAdminOperateSetprocess_batch(obj);
        let form = this.form;
        this.postAdminCodeGetpocessingcodelist(form);
        this.dialogVisiblePC = false;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
    async onExportSubmitZc() {
      this.loading = true;
      let { multipleSelection } = this;
      let arrlist = [];
      for (let index = 0; index < multipleSelection.length; index++) {
        let data = multipleSelection[index];
        let obj = {
          id: data.id,
          num: data.num,
        };
        arrlist.push(obj);
      }
      let obj = {
        arrlist,
      };
      try {
        await postAdminCodeSetshenqing(obj);
        this.$message.success("成功");
        this.handleCloseR();
        let form = this.form;
        this.postCodegetPocessinglist(form);
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
    async onPocessingZc(row) {
      this.loading = true;
      this.row = row;
      let obj = {
        processing_code: row.processing_code,
        page: 1,
        size: 100000,
      };
      try {
        let res = await postCodegetPocessinglist(obj);
        let tableReturn = res.data;
        tableReturn = tableReturn.map((e) => {
          e.num = 0;
          return e;
        });
        this.tableReturn = tableReturn;
        this.multipleSelection = [];
        this.dialogVisibleZC = true;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
    async onPocessingKC(row) {
      this.loading = true;
      this.row = row;
      let obj = {
        type_no: row.type_no,
        page: 1,
        size: 10000,
      };
      try {
        let res = await postAdminOperateget_jyamout(obj);
        let tableReturn = res.data;
        this.tableReturn = tableReturn;
        this.multipleSelection = [];
        this.dialogVisibleKC = true;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
    onPocessingPc(row) {
      this.processing_code = row.processing_code;
      this.dialogVisiblePC = true;
    },
    // 批次
    async postAdminOperateGetbatch() {
      let obj = {
        page: 1,
        size: 10000,
      };
      let res = await postAdminOperateGetbatch(obj);
      let data = res.data;
      let arr = [];
      for (let index = 0; index < data.length; index++) {
        if (data[index].status == 1) {
          arr.push(data[index]);
        }
      }
      this.pclist = arr;
    },
    // 加工厂列表
    async postHomeCodeGetFactory() {
      let obj = {
        page: 1,
        size: 1000,
      };
      await postHomeCodeGetFactory(obj).then((res) => {
        this.factoryList = res.data;
      });
    },
    async onExportSubmit() {
      let { supplier_id } = this;
      window.open(
        `https://ssy.13yu.com//index.php/Admin/Excel/processingWeiruku?supplier_id=${supplier_id}`
      );
    },
    async onExportYY() {
      let { form } = this;
      window.open(
        `https://ssy.13yu.com//index.php/Admin/Excel/processingWeiruku_yuny?sku_code=${form.sku_code}`
      );
    },

    // 导出弹窗
    async onExport() {
      this.dialogVisibleExport = true;
    },
    handleCloseR() {
      this.row = "";
      this.tableReturn = [];
      this.multipleSelection = [];
      this.dialogVisible = false;
      this.dialogVisibleB = false;
      this.dialogVisibleZC = false;
      this.dialogVisibleKC = false;
    },
    // 结案
    onPocessingFstatus(row) {
      let _this = this;
      let data = {
        processing_code: row.processing_code,
      };
      this.$confirm("确定强制完成?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            await postAdminCodeSetpocessingFstatus(data);
            _this.postAdminCodeGetpocessingcodelist(_this.form);
          } catch (error) {}
        })
        .catch(() => {});
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (
          !values.every((value) => isNaN(value)) &&
          (column.label == "件数" ||
            column.label == "入库数" ||
            column.label == "未入库数" ||
            column.label == "下单数" ||
            column.label == "增裁数" ||
            column.label == "报次数" ||
            column.label == "溢装比数")
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] = sums[index];
        } else {
          sums[index] = "";
        }
      });
      return sums;
    },
    cellStyle(row) {
      if (row.column.label == "未入库数") {
        return {
          color: "red",
          background: "#F5F7FA",
        };
      }
    },
    headerCellStyle(row) {
      if (row.column.label == "未入库数") {
        return {
          color: "red",
          background: "#F5F7FA",
        };
      }
      if (
        row.column.label == "下单数" ||
        row.column.label == "增裁数" ||
        row.column.label == "报次数" ||
        row.column.label == "入库数" ||
        row.column.label == "溢装比数" ||
        row.column.label == "聚水潭-巨益(入库数)"
      ) {
        return {
          background: "#F0F9EB",
        };
      }
    },
    ClickQty(row) {
      if (row.processing_code)
        return this.$router.push({
          name: "ContractReturnNote",
          params: { processing_code: row.processing_code },
        });
      return;
    },
    onInput(e, row, index) {
      e = e.replace(/[^0-9.]/g, "");
      let { tableReturn, multipleSelection } = this;
      let tmpObj = tableReturn[index];
      tmpObj.num = e;
      this.$set(this.tableReturn, index, tmpObj);
      for (let idx = 0; idx < multipleSelection.length; idx++) {
        if (multipleSelection[idx] == row) {
          multipleSelection[idx] = row;
        }
      }
      this.multipleSelection = multipleSelection;
    },
    onChangeInput(row) {
      this.$refs.textDocRef.toggleRowSelection(row);
    },
    handleSelectionChangeTH(val) {
      this.multipleSelection = val;
    },
    // 采购退货确认
    async onOK() {
      this.loading = true;
      let { multipleSelection, groups } = this;
      let obj = {
        arrlist: multipleSelection,
        groups,
      };
      try {
        let res = await postAdminOmsSetPurchaseReturn(obj);
        let form = this.form;
        this.postAdminCodeGetpocessingcodelist(form);
        this.$message.success("成功");
        this.loading = false;
        this.handleCloseR();
      } catch (error) {
        this.loading = false;
      }
    },
    // 报次数确认
    async onOKBao() {
      this.loading = true;
      let { multipleSelection } = this;
      let obj = {
        arrlist: multipleSelection,
      };
      try {
        let res = await postAdminProductionSaveBaonumber(obj);
        let form = this.form;
        this.postAdminCodeGetpocessingcodelist(form);
        this.$message.success("成功");
        this.loading = false;
        this.handleCloseR();
      } catch (error) {
        this.loading = false;
      }
    },

    // 采购退货
    async onReturn(row, groups) {
      this.row = row;
      this.groups = groups;
      let obj = {
        processing_code: row.processing_code,
      };
      let res = await postAdminOmsGetProType(obj);
      let tableReturn = res.data;
      tableReturn = tableReturn.map((e) => {
        e.num = 0;
        return e;
      });
      this.tableReturn = tableReturn;
      this.multipleSelection = [];
      this.dialogVisible = true;
    },
    // 报次数
    async onBao(row) {
      this.row = row;
      let obj = {
        processing_code: row.processing_code,
      };
      let res = await postAdminOmsGetProType(obj);
      let tableReturn = res.data;
      tableReturn = tableReturn.map((e) => {
        e.num = 0;
        return e;
      });
      this.tableReturn = tableReturn;
      this.multipleSelection = [];
      this.dialogVisibleB = true;
    },
    onUpdate() {
      this.loading = true;
      let form = this.form;

      postAdminOperatesave_processing_order()
        .then((res) => {
          this.postAdminCodeGetpocessingcodelist(form);
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 推送聚水潭
    // onPush(id) {
    //   let obj = {
    //     id,
    //   };
    //   let form = this.form;
    //   this.$confirm(`确定推送聚水潭?`, "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(() => {
    //       postAdminCodeSetJushuitanPurchaseUpload_shou(obj).then((res) => {
    //         this.$message({
    //           type: "success",
    //           message: "成功",
    //         });
    //         this.postAdminCodeGetpocessingcodelist(form);
    //       });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "已取消推送",
    //       });
    //     });
    // },
    // 取消
    onCancel(processing_code) {
      let obj = {
        processing_code,
      };
      let form = this.form;
      this.$confirm(`确定取消推送OMS?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOmscancelProcessing(obj).then((res) => {
            this.$message({
              type: "success",
              message: "取消成功",
            });
            this.postAdminCodeGetpocessingcodelist(form);
          });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消推送",
          // });
        });
    },
    // 推送
    onPush(processing_code) {
      let obj = {
        processing_code,
      };
      let form = this.form;
      this.$confirm(`确定推送OMS?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOmsaddWarehousingProcessing(obj).then((res) => {
            this.$message({
              type: "success",
              message: "成功",
            });
            this.postAdminCodeGetpocessingcodelist(form);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消推送",
          });
        });
    },
    // 生成RFID
    onCreate(e) {
      let { multipleSelection, form } = this;
      this.$confirm(
        `确定${
          e == 1
            ? "生成RFID洗水唛"
            : e == 2
            ? "无需生成RFID"
            : e == 3
            ? "生成RFID吊牌"
            : ""
        }?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          let obj = {
            ids: [],
            status: e,
          };
          multipleSelection.forEach((res) => {
            obj.ids.push(res.id);
          });
          postAdminCodeSetpocessingcodestatus(obj).then((res) => {
            this.$message({
              type: "success",
              message: "成功",
            });
            this.postAdminCodeGetpocessingcodelist(form);
          });
        })
        .catch(() => {});
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 列表
    async postAdminCodeGetpocessingcodelist(data) {
      this.loading = true;
      this.form = data;
      data = JSON.parse(JSON.stringify(data));
      let date = data.str_add_date;
      if (date) {
        if (Array.isArray(date)) {
          data.str_add_date = date[0];
          data.end_add_date = date[1];
        }
      } else {
        this.form.str_add_date = "";
        this.form.end_add_date = "";
      }
      this.$refs.multipleTable.clearSelection();
      postAdminCodeGetpocessingcodelist(data)
        .then((res) => {
          this.loading = false;
          this.savetime = res.savetime;
          let data = res.data;
          for (let index = 0; index < data.length; index++) {
            data[index].wrks =
              Number(data[index].num) -
              // Number(data[index].zc_num) -
              Number(data[index].bao_number) -
              Number(data[index].qty);
          }
          this.tableData = data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminCodeGetpocessingcodelist(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
